#include "m0wig.h"
#include "ui_m0wig.h"

#define TOPIC_DATA_UP       "/app/data/up"
#define TOPIC_DATA_DOWN     "/app/data/down"
#define TOPIC_CTL_UP        "/app/control/up"
#define TOPIC_CTL_DOWN      "/app/control/down"

M0Wig::M0Wig(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::M0Wig)
{
    ui->setupUi(this);


}

M0Wig::~M0Wig()
{
    delete ui;
}



//背景图片
void M0Wig::paintEvent(QPaintEvent *event)
{

    //    QPainter painter(this);

    //    int x = (width()-width()*0.45)/2;
    //    int y = (height()-width()*0.45)/2;
    //    int a = width()*0.45;
    //    QRadialGradient radia(rect().center(),width());
    //    radia.setColorAt(0,Qt::white);
    //    radia.setColorAt(1,QColor(255,204,255));
    //    painter.setBrush(radia);
    //    painter.drawRect(this->rect());
    //    painter.drawPixmap(QRect(x,y,a,a),QPixmap(":/pictures/刹那.png"));



}


void M0Wig::on_button_1_clicked()
{
    QMQTT::Message msg;
    msg.setTopic(TOPIC_CTL_DOWN);
    msg.setPayload("{\"mode\":1}");
    qDebug() << "[M0]:" << "{\"mode\":1}";
    GlobalVal::mqtt->publish(msg);
}

void M0Wig::on_button_2_clicked()
{
    QMQTT::Message msg;
    msg.setTopic(TOPIC_CTL_DOWN);
    msg.setPayload("{\"mode\":2}");
    qDebug() << "[M0]:" << "{\"mode\":2}";
    GlobalVal::mqtt->publish(msg);
}

void M0Wig::on_button_3_clicked()
{
    QMQTT::Message msg;
    msg.setTopic(TOPIC_CTL_DOWN);
    msg.setPayload("{\"mode\":3}");
    qDebug() << "[M0]:" << "{\"mode\":3}";
    GlobalVal::mqtt->publish(msg);
}
